<?php

Yii::import('common.models._base.BaseLocalityName');

class LocalityName extends BaseLocalityName {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public static function getlocaltyLatLogn($id, $address) {
        $address = $address . ',' . SkillConfig::locality_Adress;
        $Address = urlencode($address);
        $request_url = "http://maps.googleapis.com/maps/api/geocode/xml?address=" . $Address . "&sensor=true";
        $xml = simplexml_load_file($request_url) or die("url not loading");
        $status = $xml->status;
        if ($status == "OK") {
            $model = LocalityName::model()->findByPk((int) $id);
            $Lat = $xml->result->geometry->location->lat;
            $Lon = $xml->result->geometry->location->lng;
            $LatLng = "$Lat,$Lon";
            $model->setAttribute('latitude', $Lat);
            $model->setAttribute('longitude', $Lon);
            $model->save();
        }
    }

    public static function getvenueName($data) {
        $venueName = ClassVenue::model()->findByAttributes(array('venue_locality' =>trim($data->locality_name), 'users_id' => $data->users_id));
        
        if (!empty($venueName)) {
            return $venueName->name . ',' . $venueName->address_line1 . ',' . $venueName->address_line2 . ',' . $venueName->venue_locality . ',' . $venueName->state->name . '-' . $venueName->zip_code;
        }
    }

}